package com.iflytek.springboot_medicine.repository;

import com.iflytek.springboot_medicine.entity.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface OrderRepository extends JpaRepository<Order, Long> {
    List<Order> findByUserName(String userName);
    
    List<Order> findByOrderStatus(Integer orderStatus);
    
    @Query("SELECT o FROM Order o WHERE o.createTime BETWEEN :startDate AND :endDate")
    List<Order> findByDateRange(@Param("startDate") Date startDate, @Param("endDate") Date endDate);
    
    @Query("SELECT o FROM Order o WHERE o.userName = :userName AND o.createTime BETWEEN :startDate AND :endDate")
    List<Order> findByUserNameAndDateRange(
        @Param("userName") String userName,
        @Param("startDate") Date startDate,
        @Param("endDate") Date endDate
    );
} 